# coding=utf-8
"""
作者：董新强 
创建时间：
描述：
"""
import requests

from framework.aes_cypto import AesCrypto
from framework.utilities import to_string


class CatServeApiTest:
    def __init__(self):
        self._appid = '145fc0f695bb11cdfd4214dda9040caz'
        self._key = 'jZaq3TrSiUAKo5GWymd8ga0hkIwx1FRfsN7uEnXcmd6'
        self._aes = AesCrypto(self._key)
        self._host = r'http://127.0.0.1:9000/{}'

    def post_body(self, data):
        return {
            'id': self._appid,
            'data': self._aes.encrypt(to_string(data))
        }

    def test_start(self):
        data = {
            'uid': 1,
            'aid': 1
        }
        resp = requests.post(self._host.format('catapi/answer/start'), json=self.post_body(data))
        print(resp.json())

    def test_answer(self, tid, qid, answer):
        data = {
            'tid': tid,
            'qid': qid,
            'answer': answer
        }
        resp = requests.post(self._host.format('catapi/answer/answer'), json=self.post_body(data))
        print(resp.json())


if __name__ == '__main__':
    csat = CatServeApiTest()
    # csat.test_start()
    tid = 4
    qid = input('qid=>')
    answer = input('answer=>')
    while tid and qid and answer:
        csat.test_answer(tid, qid, answer)
        qid = input('qid=>')
        answer = input('answer=>')
